namespace core {
    export class ControllerManager extends BaseClass {
        private _modules: any;

        public constructor() {
            super();
            this._modules = {};
        }

        public clear(): void {
            this._modules = {};
        }
        public register(key: number, control: BaseController): void {
            if (this.isExists(key))
                return;

            this._modules[key] = control;
        }
        public unregister(key: number): void {
            if (!this.isExists(key))
                return;

            this._modules[key] = null;
            delete this._modules[key];
        }
        public isExists(key: number): boolean {
            return this._modules[key] != null;
        }

        public applyFunc(controllerD: number, key: number, ...param: any[]): any {
            var manager: BaseController = this._modules[controllerD];
            if (manager) {
                //TODO: 这是什么意思，为啥不直接用param
                var params = [];
                for (var i = 1; i < arguments.length; i++) {
                    params[i - 1] = arguments[i];
                }
                return manager.applyFunc.apply(manager, params);
            } else {
                console.debug("模块" + controllerD + "不存在");
                return null;
            }
        }
        public getControllerModel(controllerD: number): BaseModel {
            var manager: BaseController = this._modules[controllerD];
            if (manager) {
                return manager.getModel();
            }
            return null;
        }
    }
}